﻿

//Please add references
using CardRegisterCollection.DBUtility;
using System;
using System.Data;
using System.Data.OleDb;
using System.Text;

namespace CardRegisterCollection.DAL
{
    /// <summary>
    /// 数据访问类:domestic_attendee
    /// </summary>
    public partial class DomesticAttendee
    {
        public DomesticAttendee()
        { }

        public bool Delete(string Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from domestic_attendee ");
            strSql.Append(" where Id=@Id ");
            OleDbParameter[] parameters = {
                    new OleDbParameter("@Id", OleDbType.VarChar,50)         };
            parameters[0].Value = Id;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 获取满足当前的境内人员数据
        /// </summary>
        /// <returns></returns>
        public DataSet GetList()
        {
            string strDb = "select * from domestic_attendee where deleflag = @deleflag ";
            OleDbParameter[] parameters = {
                    new OleDbParameter("@deleflag", OleDbType.Boolean)         };
            parameters[0].Value = false;

            return DbHelperOleDb.Query(strDb, parameters);
        }

        public DataSet Query(string str)
        {
            string strDb = "select * from domestic_attendee  where deleflag = @deleflag  and " + str;

            OleDbParameter[] parameters = {
                    new OleDbParameter("@deleflag", OleDbType.Boolean)         };
            parameters[0].Value = false;

            return DbHelperOleDb.Query(strDb, parameters);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.DomesticAttendee model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into domestic_attendee(");
            strSql.Append("Id,Name, Gender,IDNumber,CardType,WorkUnit,CreatedBy,CreatedAt,UserDefine1)");
            strSql.Append(" values (");
            strSql.Append("@Id,@Name, @Gender, @IDNumber,@CardType,@WorkUnit,@CreatedBy,@CreatedAt,@UserDefine1)");

            OleDbParameter[] parameters = {
                new OleDbParameter("@Id", OleDbType.VarChar, 255),
                new OleDbParameter("@Name", OleDbType.VarChar, 255),
                new OleDbParameter("@Gender", OleDbType.VarChar, 255),
                new OleDbParameter("@IDNumber", OleDbType.VarChar, 255),
                new OleDbParameter("@CardType", OleDbType.VarChar, 255),
                new OleDbParameter("@WorkUnit", OleDbType.VarChar, 255),
                new OleDbParameter("@CreatedBy", OleDbType.VarChar, 255),
                new OleDbParameter("@CreatedAt", OleDbType.Date),
                new OleDbParameter("@UserDefine1", OleDbType.VarChar, 255),
            };
            parameters[0].Value = model.Id;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.Gender;
            parameters[3].Value = model.IDNumber;
            parameters[4].Value = model.CardType;
            parameters[5].Value = model.WorkUnit;
            parameters[6].Value = model.CreatedBy;
            parameters[7].Value = model.CreatedDate;
            parameters[8].Value = model.UserDefine1;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool Exit(string idNum)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from domestic_attendee where ");
            strSql.Append("IDNumber = @IDNumber");
            OleDbParameter[] parameters = {
                new OleDbParameter("@IDNumber", OleDbType.VarChar, 255),
            };
            parameters[0].Value = idNum;
            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //public bool Add(Model.DomesticAttendee model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("insert into domestic_attendee(");
        //    strSql.Append("Id,BatchNo,Name,BirthDate,Gender,RegistrationProvince,RegistrationCity,RegistrationAddress,CurrentResidenceProvince,CurrentResidenceCity,CurrentResidenceAddress, IDNumber,CardType,HolderOfCertificateType,TrafficArea,WorkUnit,Telephone,Remark,UserDefine1,UserDefine2,UserDefine3,UserDefine4,UserDefine5,UserDefine6,UserDefine7,UserDefine8,UserDefine9,UserDefine10,CreatedBy,CreatedAt,DeleteFlag,LastUpdatedBy,LastUpdatedAt)");
        //    strSql.Append(" values (");
        //    strSql.Append("@Id,@BatchNo,@Name,@BirthDate,@Gender,@RegistrationProvince,@RegistrationCity,@RegistrationAddress,@CurrentResidenceProvince,@CurrentResidenceCity,CurrentResidenceAddress, @IDNumber,@CardType,@HolderOfCertificateType,@TrafficArea,@WorkUnit,@Telephone,@Remark,@UserDefine1,@UserDefine2,@UserDefine3,@UserDefine4,@UserDefine5,@UserDefine6,@UserDefine7,@UserDefine8,@UserDefine9,@UserDefine10,@CreatedBy,@CreatedAt,@DeleteFlag,@LastUpdatedBy,@LastUpdatedAt)");
        //    OleDbParameter[] parameters = {
        //        new OleDbParameter("@Id", OleDbType.VarChar, 255),
        //        new OleDbParameter("@BatchNo", OleDbType.VarChar, 255), 
        //        new OleDbParameter("@Name", OleDbType.VarChar, 255),
        //        new OleDbParameter("@BirthDate", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Gender", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationProvince", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationCity", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationAddress", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceProvince", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceCity", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceAddress", OleDbType.VarChar, 255),
        //        new OleDbParameter("@IDNumber", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CardType", OleDbType.VarChar, 255),
        //        new OleDbParameter("@HolderOfCertificateType", OleDbType.VarChar, 255),
        //        new OleDbParameter("@TrafficArea", OleDbType.VarChar, 255),
        //        new OleDbParameter("@WorkUnit", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Telephone", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Remark", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine1", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine2", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine3", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine4", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine5", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine6", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine7", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine8", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine9", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine10", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CreatedBy", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CreatedAt", OleDbType.Date),
        //        new OleDbParameter("@DeleteFlag", OleDbType.Boolean, 1),
        //        new OleDbParameter("@LastUpdatedBy", OleDbType.VarChar, 255),
        //        new OleDbParameter("@LastUpdatedAt", OleDbType.Date)
        //    };
        //    parameters[0].Value = model.Id;
        //    parameters[1].Value = model.BatchNo;
        //    parameters[2].Value = model.Name;
        //    parameters[3].Value = model.BirthDate;
        //    parameters[4].Value = model.Gender;
        //    parameters[5].Value = model.RegistrationProvince;
        //    parameters[6].Value = model.RegistrationCity;
        //    parameters[7].Value = model.RegistrationAddress;
        //    parameters[8].Value = model.CurrentResidenceProvince;
        //    parameters[9].Value = model.CurrentResidenceCity;
        //    parameters[10].Value = model.CurrentResidenceAddress; 
        //    parameters[11].Value = model.IDNumber;
        //    parameters[12].Value = model.CardType;
        //    parameters[13].Value = model.HolderOfCertificateType;
        //    parameters[14].Value = model.TrafficArea;
        //    parameters[15].Value = model.WorkUnit;
        //    parameters[16].Value = model.Telephone;
        //    parameters[17].Value = model.Remark;
        //    parameters[18].Value = model.UserDefine1;
        //    parameters[19].Value = model.UserDefine2;
        //    parameters[20].Value = model.UserDefine3;
        //    parameters[21].Value = model.UserDefine4;
        //    parameters[22].Value = model.UserDefine5;
        //    parameters[23].Value = model.UserDefine6;
        //    parameters[24].Value = model.UserDefine7;
        //    parameters[25].Value = model.UserDefine8;
        //    parameters[26].Value = model.UserDefine9;
        //    parameters[27].Value = model.UserDefine10;
        //    parameters[28].Value = model.CreatedBy;
        //    parameters[29].Value = model.CreatedDate;
        //    parameters[30].Value = model.DeleteFlag;
        //    parameters[31].Value = model.LastUpdatedBy;
        //    parameters[32].Value = model.LastUpdatedDate;

        //    int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        public bool Update(Model.DomesticAttendee model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update domestic_attendee set ");
            strSql.Append("Name=@Name,");
            strSql.Append("Gender=@Gender,");
            strSql.Append("IDNumber=@IDNumber,");
            strSql.Append("CardType=@CardType,");
            strSql.Append("WorkUnit=@WorkUnit,");
            strSql.Append("LastUpdatedBy=@LastUpdatedBy,");
            strSql.Append("LastUpdatedAt=@LastUpdatedAt ,");

            strSql.Append("UserDefine1=@UserDefine1 ");

            strSql.Append(" where Id=@Id ");
            OleDbParameter[] parameters = {
                new OleDbParameter("@Name", OleDbType.VarChar, 255),
                new OleDbParameter("@Gender", OleDbType.VarChar, 255),
                new OleDbParameter("@IDNumber", OleDbType.VarChar, 255),
                new OleDbParameter("@CardType", OleDbType.VarChar, 255),
                new OleDbParameter("@WorkUnit", OleDbType.VarChar, 255),
                new OleDbParameter("@LastUpdatedBy", OleDbType.VarChar, 255),
                new OleDbParameter("@LastUpdatedAt", OleDbType.Date),
                new OleDbParameter("@UserDefine1",OleDbType.VarChar, 255),
                new OleDbParameter("@Id", OleDbType.VarChar, 255),
            };

            parameters[0].Value = model.Name;
            parameters[1].Value = model.Gender;
            parameters[2].Value = model.IDNumber;
            parameters[3].Value = model.CardType;
            parameters[4].Value = model.WorkUnit;
            parameters[5].Value = model.LastUpdatedBy;
            parameters[6].Value = model.LastUpdatedDate;
            parameters[7].Value = model.UserDefine1;
            parameters[8].Value = model.Id;

            int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //public bool Update(Model.DomesticAttendee model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("update domestic_attendee set ");
        //    strSql.Append("Id=@Id,");
        //    strSql.Append("Name=@Name,");
        //    strSql.Append("BirthDate=@BirthDate,");
        //    strSql.Append("Gender=@Gender,");
        //    strSql.Append("RegistrationProvince=@RegistrationProvince,");
        //    strSql.Append("RegistrationCity=@RegistrationCity,");
        //    strSql.Append("RegistrationAddress=@RegistrationAddress,");
        //    strSql.Append("CurrentResidenceProvince=@CurrentResidenceProvince,");
        //    strSql.Append("CurrentResidenceCity=@CurrentResidenceCity,");
        //    strSql.Append("CurrentResidenceAddress=@CurrentResidenceAddress,");
        //    strSql.Append("IDNumber=@IDNumber,");
        //    strSql.Append("CardType=@CardType,");
        //    strSql.Append("HolderOfCertificateType=@HolderOfCertificateType,");
        //    strSql.Append("TrafficArea=@TrafficArea,");
        //    strSql.Append("WorkUnit=@WorkUnit,");
        //    strSql.Append("Telephone=@Telephone,");
        //    strSql.Append("Remark=@Remark,");
        //    strSql.Append("UserDefine1=@UserDefine1,");
        //    strSql.Append("UserDefine2=@UserDefine2,");
        //    strSql.Append("UserDefine3=@UserDefine3,");
        //    strSql.Append("UserDefine4=@UserDefine4,");
        //    strSql.Append("UserDefine5=@UserDefine5,");
        //    strSql.Append("UserDefine6=@UserDefine6,");
        //    strSql.Append("UserDefine7=@UserDefine7,");
        //    strSql.Append("UserDefine8=@UserDefine8,");
        //    strSql.Append("UserDefine9=@UserDefine9,");
        //    strSql.Append("UserDefine10=@UserDefine10,");
        //    strSql.Append("DeleteFlag=@DeleteFlag,");
        //    strSql.Append("LastUpdatedBy=@LastUpdatedBy,");
        //    strSql.Append("LastUpdatedAt=@LastUpdatedAt,");
        //    strSql.Append(" where Id=@Id ");
        //    OleDbParameter[] parameters = {
        //        new OleDbParameter("@Id", OleDbType.VarChar, 255),
        //        new OleDbParameter("@BatchNo", OleDbType.VarChar, 255),
        //        new OleDbParameter("@BirthDate", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Gender", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationProvince", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationCity", OleDbType.VarChar, 255),
        //        new OleDbParameter("@RegistrationAddress", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceProvince", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceCity", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CurrentResidenceAddress", OleDbType.VarChar, 255),
        //        new OleDbParameter("@IDNumber", OleDbType.VarChar, 255),
        //        new OleDbParameter("@CardType", OleDbType.VarChar, 255),
        //        new OleDbParameter("@HolderOfCertificateType", OleDbType.VarChar, 255),
        //        new OleDbParameter("@TrafficArea", OleDbType.VarChar, 255),
        //        new OleDbParameter("@WorkUnit", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Telephone", OleDbType.VarChar, 255),
        //        new OleDbParameter("@Remark", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine1", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine2", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine3", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine4", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine5", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine6", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine7", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine8", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine9", OleDbType.VarChar, 255),
        //        new OleDbParameter("@UserDefine10", OleDbType.VarChar, 255),
        //        new OleDbParameter("@DeleteFlag", OleDbType.Boolean, 1),
        //        new OleDbParameter("@LastUpdatedBy", OleDbType.VarChar, 255),
        //        new OleDbParameter("@LastUpdatedAt", OleDbType.Date)
        //    };
        //    parameters[0].Value = model.Id;
        //    parameters[1].Value = model.BatchNo;
        //    parameters[2].Value = model.Name;
        //    parameters[3].Value = model.BirthDate;
        //    parameters[4].Value = model.Gender;
        //    parameters[5].Value = model.RegistrationProvince;
        //    parameters[6].Value = model.RegistrationCity;
        //    parameters[7].Value = model.RegistrationAddress;
        //    parameters[8].Value = model.CurrentResidenceProvince;
        //    parameters[9].Value = model.CurrentResidenceCity;
        //    parameters[10].Value = model.CurrentResidenceAddress;
        //    parameters[11].Value = model.IDNumber;
        //    parameters[12].Value = model.CardType;
        //    parameters[13].Value = model.HolderOfCertificateType;
        //    parameters[14].Value = model.TrafficArea;
        //    parameters[15].Value = model.WorkUnit;
        //    parameters[16].Value = model.Telephone;
        //    parameters[17].Value = model.Remark;
        //    parameters[18].Value = model.UserDefine1;
        //    parameters[19].Value = model.UserDefine2;
        //    parameters[20].Value = model.UserDefine3;
        //    parameters[21].Value = model.UserDefine4;
        //    parameters[22].Value = model.UserDefine5;
        //    parameters[23].Value = model.UserDefine6;
        //    parameters[24].Value = model.UserDefine7;
        //    parameters[25].Value = model.UserDefine8;
        //    parameters[26].Value = model.UserDefine9;
        //    parameters[27].Value = model.UserDefine10;

        //    parameters[28].Value = model.DeleteFlag;
        //    parameters[29].Value = model.LastUpdatedBy;
        //    parameters[30].Value = model.LastUpdatedDate;




        //    int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        ////}
    }
}

